package work.chenxr.restful.encrypt.controller;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import work.chenxr.restful.encrypt.annotation.ApiSecurity;
import work.chenxr.restful.encrypt.entity.TestEntity;

/**
 * @Author Chenxr
 * @Date 2023/10/28
 * @Description
 */
@RestController
public class RestfulEncryptController {

    @ApiSecurity(decrypt = false)
    @GetMapping(value = "/encrypt", produces = MediaType.APPLICATION_JSON_VALUE)
    public TestEntity encrypt() {
        TestEntity testEntity = new TestEntity();
        testEntity.setId(1L);
        testEntity.setContent("加密前的内容");
        return testEntity;
    }

    @ApiSecurity
    @PostMapping(value = "/decrypt", produces = MediaType.APPLICATION_JSON_VALUE)
    public TestEntity decrypt(@RequestBody TestEntity testEntity) {
        return testEntity;
    }
}
